import hyRequest from "../..";
import { getCurrentToken } from "../login";
const token = getCurrentToken();

/**
 * @获取视频列表
 * @param query
 * @returns
 */
export function getVideoList(query: { pageSize: number; pageNum: number }) {
  return hyRequest.get({
    url: "/video/list",
    headers: {
      Authorization: `Bearer ${token}`,
    },
    params: query,
  });
}
/**
 * @获取视频详细
 * @param id
 * @returns
 */
export function getDetailVideoInfo(id: number) {
  return hyRequest.get({
    url: `/video/${id}`,
    headers: {
      Authorization: `Bearer ${token}`,
    },
  });
}

/**
 *@新增
 * @param body
 * @returns
 */
export function addVideo(body: {
  createBy: null | string;
  createTime: string | null;
  department: string;
  fileName: string | null;
  id: null | number;
  remark: null;
  state: string;
  sysDeptId: null | number;
  title: string;
  updateBy: null;
  updateTime: null;

  video: string | null;
}) {
  return hyRequest.post({
    url: "/video/upload",
    headers: {
      Authorization: `Bearer ${token}`,
    },
    data: body,
  });
}

/**
 * @修改
 * @param body
 * @returns
 */
export function modifyVideo(body: {
  createBy: string | null;
  createTime: string | null;
  department: string;
  fileName: string | null;
  id: number | null;
  remark: null;
  state: string;
  sysDeptId: null;
  title: string;
  updateBy: string;
  updateTime: string | null;
  userId: null;
  video: null | string;
}) {
  return hyRequest.put({
    url: "video",
    headers: {
      Authorization: `Bearer ${token}`,
    },
    data: body,
  });
}
/**
 * @删除
 * @param ids
 * @returns
 */
export function deleteVideo(ids: any[]) {
  const idsStr = ids.join(",");
  return hyRequest.delete({
    url: `/video/${idsStr}`,
    headers: {
      Authorization: `Bearer ${token}`,
    },
  });
}

/**
 * @导出
 * @param query
 * @returns
 */
export function exportVideo(query: { pageSize: number; pageNum: number }) {
  return hyRequest.post({
    url: "/video/export",
    headers: {
      Authorization: `Bearer ${token}`,
    },
    params: query,
  });
}

/**
 * @上传文件
 * @param file
 * @returns
 */
export function uploadVideo(file: File) {
  const formData = new FormData();
  formData.append("file", file);
  return hyRequest.post({
    url: "/common/upload",
    headers: {
      Authorization: `Bearer ${token}`,
      "Content-Type": "multipart/form-data",
    },
    data: formData,
  });
}
